package practice1_100;

import java.util.ArrayList;

public class Practice230 {
   // int a = 1;
//    int temp=0;
    ArrayList<Integer> list=new ArrayList<>();

    public int kthSmallest(TreeNode root, int k) {
        //笨方法,本来想用k--的方法，但是调试很久不对，放弃了，
        //先遍历，用list接受每个节点，找到k个节点
        kth(root);
        return list.get(k-1);
//        for (int i=1;i<=k;i++){
//            list
//        }
    }
    public void kth(TreeNode root) {
        if(root==null) return;
        kth(root.left);
        list.add(root.val);
        kth(root.right);
    }

    public static void main(String[] args) {
//        [5,3,6,2,4,null,null,1]
        TreeNode treeNode = new TreeNode(5, new TreeNode(3, new TreeNode(2,new TreeNode(1),null), new TreeNode(4)), new TreeNode(6));
        int a = new Practice230().kthSmallest(treeNode, 3);
        System.out.println(a);
    }
}
